
import * as Cesium from "cesium";

export const CesiumViewer = (mapContainer:string)=>{


// 设置默认视角在中国
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);

// 取消Cesium自带的一些内容
const viewer = new Cesium.Viewer(mapContainer, {
    infoBox: false,
    geocoder: false,
    homeButton: false,
    sceneModePicker: false,
    baseLayerPicker: false,
    navigationHelpButton: false,
    animation: false,
    // creditContainer: "credit",
    timeline: false,
    fullscreenButton: false,
    vrButton: false,
    // terrain: Cesium.Terrain.fromWorldTerrain(),
    imageryProvider: new Cesium.SingleTileImageryProvider({
        url:"",
    }),//影像服务提供者必须创建
});

// 去除cesium的logo
viewer.cesiumWidget.creditContainer.style.display = "none";

// NOTE:修改鼠标操作习惯
// 将原来鼠标中键倾斜视图修改为鼠标左键拖动
viewer.scene.screenSpaceCameraController.tiltEventTypes = [
  Cesium.CameraEventType.RIGHT_DRAG,
];
// 将原来鼠标右键拖动缩放修改为鼠标滚轮滚动
viewer.scene.screenSpaceCameraController.zoomEventTypes = [
  Cesium.CameraEventType.WHEEL,
];

// 开启深度检测，保证一定情况下地形可以遮挡viewer.entities
viewer.scene.globe.depthTestAgainstTerrain = true;


// NOTE:背景图--需要使用URL来解析jpg图片
let imageryProvider = new Cesium.SingleTileImageryProvider({
    url: new URL('@/assets/8081_earthmap2k.jpg', import.meta.url).href
});
viewer.imageryLayers.addImageryProvider(imageryProvider);

// 设置相机的 near 和 far 
viewer.scene.camera.frustum.near = 0.1;
// viewer.scene.camera.frustum.far = 10000000.0;


return viewer;
}
